package com.xiaoxu.intranetweb.dom4jUtil.config;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class SystemConfigReader {
//    拿到是否是本地服務的配置

    public String systemConfig(String elementName) {
        String result = null;
        try {
            SAXReader reader = new SAXReader();
            String path = System.getProperty("user.dir");
            Document document = reader.read(new File(path + "/config/systemConfig.config"));
            Element root = document.getRootElement();

            // Find the element by its name and get its text value
            Element element = root.element(elementName);
            if (element != null) {
                result = element.getText();
            }
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
//    读取是本地还是云端（0是本地1是云端）
    public String isLocalOrCloud() {
        return systemConfig("isLocalOrCloud");
    }
//    是否开启微信消息推送
    public String isWxMsgPush() {
        return systemConfig("wxMsgPushEn");
    }

//    公司电厂切换
public String switchGsOrDc() {
    return systemConfig("switchGsOrDc");
}
}
